{% extends 'layout/manage.html' %}
{% load static %}

{% block css %}
    <style>
        #create-project{
            margin-bottom: 15px;
        }
        /*
        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: center;
            flex-wrap: wrap;
        }

        .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;
        }

        .item:hover{
            border: 1px solid #f0ad4e;
        }

        .item > .title{
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .item > .info{
            padding: 10px 10px;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;
        }

        .item >.info > .info-1{
            float: left;
        }

        .item > .info > .info-2{
            float: right;
        }

        .item > .info a {
            text-decoration: none;
        }

        .item > .info .fa-star-o{
            font-size: 10px;
        }*/

        .panel-body > .item{
            float: left;
            margin-right: 15px;
            margin-bottom: 15px;
            {#padding: 0;#}
            {#display: flex;#}
            {#flex-direction: row;#}
            {#justify-content: left;#}
            {#align-items: center;#}
            {#flex-wrap: wrap;#}
        }

         .item:hover{
            border: 2px solid #f0ad4e;
        }
         .item > .info {
             height: 38px;
         }
         .item:hover > .info > .info-1,
         .item:hover > .info > .info-2{
             top: 9px;

         }
         .item:hover > .title{
             height: 102px;
             line-height: 102px;
         }

        .item{
            width: 228px;
            border-radius: 6px;
            border: 1px solid #8c8c8c;
        }

        .item > .title{
            width: 100%;
            height: 104px;
            display: inline-block;
            color: white;
            line-height: 104px;
            text-align: center;
            text-decoration: none;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
        }

        .item > .info{
            position: relative;
            height: 40px;
            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
        }

        .item > .info > .info-1{
            position: absolute;
            left: 5px;
            top: 10px;
        }

        .item > .info > .info-2{
            position: absolute;
            right: 8px;
            top: 10px;
        }



        .color-radio label {
            margin: 0;
            padding: 0;
        }

        .color-radio input[type='radio'] {
            display: none;
        }

        .color-radio input[type='radio'] + .cycle {
            display: inline-block;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            border: 1px solid #dddddd;
        }

        .color-radio input[type='radio']:checked + .cycle {
            border: 2px solid rgba(5, 4, 5, 0.4);
        }

    </style>
{% endblock %}


{% block content %}
    <div class="container-fluid project">
        <a id='create-project' class="btn btn-primary" data-toggle="modal" data-target="#addModal">
            <i class="fa fa-plus-circle" aria-hidden="true"></i>
            新建项目
        </a>
        <!-- 面板  -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-star" aria-hidden="true"></i>
                星标
            </div>
            <div id="star" class="panel-body">
                {% for item in project_dict.star %}
                    <div class="item" my={{ item.type }} nid={{ item.value.id }}>
                        <a href="{% url 'app01:dashboard' project_id=item.value.id %}" class="title" style="background-color: {{ item.value.get_color_display }};">{{ item.value.name }}</a>
                        <div class="info">
                            <div class="info-1">
{#                                <a href="{% url 'app01:project_unstar' project_type=item.type project_id=item.value.id %}">#}
{#                                    <i class="fa fa-star-o fa-lg fan" aria-hidden="true" style="color: #f0ad4e"></i>#}
{#                                </a>#}
                                <a>
                                    <i class="fa fa-star-o fa-lg fan" aria-hidden="true" style="color: #f0ad4e"></i>
                                </a>
                                <span>{{ item.value.creator.username }}</span>
                            </div>
                            <div class="info-2">
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.value.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        <!-- 面板  -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-list" aria-hidden="true"></i>
                我创建的
            </div>
            <div id="MyUnstar" class="panel-body">
                {% for item in project_dict.my %}
                    <div class="item" my="my" nid={{ item.id }}>
                        <a href="{% url 'app01:dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }};">{{ item.name }}</a>
                        <div class="info">
                            <div class="info-1">
{#                                <a href="{% url 'app01:project_star' project_type='my' project_id=item.id %}">#}
{#                                    <i class="fa fa-star-o fa-lg xiong" aria-hidden="true" style="color: #d5d5d5"></i>#}
{#                                </a>#}
                                 <a>
                                    <i class="fa fa-star-o fa-lg xiong" aria-hidden="true" style="color: #d5d5d5"></i>
                                </a>
                                <span>{{ item.creator.username }}</span>
                            </div>
                            <div class="info-2">
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        <!-- 面板  -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-handshake-o" aria-hidden="true"></i>
                我参与的
            </div>
            <div id="JoinUnstar" class="panel-body">
                {% for item in project_dict.jion %}
                    <div class="item" my="join" nid="{{ item.id }}">
                        <a href="{% url 'app01:dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }};">{{ item.name }}</a>
                        <div class="info">
                            <div>
{#                                <a href="{% url 'app01:project_star' project_type='join' project_id=item.id %}">#}
{#                                    <i class="fa fa-star-o fa-lg xiong" aria-hidden="true" style="color: #d5d5d5"></i>#}
{#                                </a>#}
                                <a>
                                    <i class="fa fa-star-o fa-lg xiong" aria-hidden="true" style="color: #d5d5d5"></i>
                                </a>
                                <span>{{ item.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>

    <!-- 模态框 -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    <form id="addForm">
                        {% csrf_token %}
                        {% for filed in obj %}
                            <div class="form-group">
                                <label for="{{ filed.id_for_label }}">{{ filed.label }}</label>
                                {{ filed }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">确 定</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}



{% block js %}
    <script>
        $('#btnSubmit').click(function () {
            $.ajax({
                url: "{% url 'app01:project' %}",
                type: 'POST',
                data: $('#addForm').serialize(),
                dataType: 'JSON',
                success: function (res) {
                    if (res.status) {
                        location.href = location.href
                        //location.reload()
                    } else {
                        $.each(res.error, function (key, value) {
                            $('#id_' + key).next().text(value[0])
                        })
                    }

                }
            })

        });

        $('.fa-star-o').click(function () {
            var starAttr = $(this).attr('class');
            if (starAttr === 'fa fa-star-o fa-lg xiong'){
                $(this).attr('style', 'color: #f0ad4e;');
                $(this).attr('class', 'fa fa-star-o fa-lg fan');
                var itemEle = $(this).parentsUntil('.panel-body').last();
                var itemAttrMy = itemEle.attr('my');
                var itemAttrNid = itemEle.attr('nid');
                $.ajax({
                url: "/app01/project/star/"+itemAttrMy+'/'+itemAttrNid+'/',
                type: 'GET',
                dataType: 'JSON',
                success: function (res) {
                    $('#star').append(itemEle);
                    {#itemEle.remove()#}
                }
            })
            }else {
                $(this).attr('style', 'color: #d5d5d5;');
                $(this).attr('class', 'fa fa-star-o fa-lg xiong');
                var itemEle = $(this).parentsUntil('.panel-body').last();
                var itemAttrMy = itemEle.attr('my');
                var itemAttrNid = itemEle.attr('nid');
                $.ajax({
                url: "/app01/project/unstar/"+itemAttrMy+'/'+itemAttrNid+'/',
                type: 'GET',
                dataType: 'JSON',
                success: function (res) {
                    if(res.result === 'my'){
                        $('#MyUnstar').append(itemEle);
                    }else {
                        $('#JoinUnstar').append(itemEle);
                    }
                }
            })
            }
        });
    </script>

{% endblock %}